﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RESTServices.Dominio;
using System.Data.SqlClient;

namespace RESTServices.Persistencia
{
    public class VehiculoCobranaDAO
    {
        public VehiculoCobranza Obtener(int numPrograma)
        {
            VehiculoCobranza detalleExistente = null;

            string sql = "SELECT h.numProgramacion, sum(peaje)as montoPeaje, SUM(detraccion) as montoDetraccion FROM tb_vehiculoCobranza vc ";
            sql = sql + "inner join tb_cobranza c on c.numero=vc.numero inner join tb_empleado e on e.codEmpleado=c.codEmpleado ";
            sql = sql + "inner join tb_horario h on e.codEmpleado=h.codEmpleado where h.numProgramacion=@item group by h.numProgramacion";

            using (SqlConnection con = new SqlConnection(ConexionUtil.Cadena))
            {
                con.Open();
                using (SqlCommand com = new SqlCommand(sql, con))
                {
                    com.Parameters.Add(new SqlParameter("@item", numPrograma));
                    using (SqlDataReader resultado = com.ExecuteReader())
                    {
                        if (resultado.Read())
                        {
                            detalleExistente = new VehiculoCobranza()
                            {
                                // Item= (int)resultado["item"],
                                //Fec = (DateTime)resultado["fecha"],
                                //MontoPeaje = (double)resultado["montoPeaje"],
                                //MontoDetraccion = (double)resultado["montoDetraccion"],
                                //NumProgramacion = (int)resultado["numProgramacion"],
                            };
                        }
                    }
                }
            }
            return detalleExistente;
        }
    }
}